package com.prathiba.jumbledword;

import java.util.Set;

/**
 * Generates the jumbled word to the user
 * 
 */
public class JumbledWordGenerator {

	/**
	 * Checks whether the new jumbled word generated has not already been
	 * displayed to the user and returns a new jumbled word.
	 * 
	 * @param wordsViewedByUser
	 * @param allJumbledWords
	 * @return newWord
	 */
	public String jumbledWordNotIn(Set<String> wordsViewedByUser,
			Set<String> allJumbledWords) {

		allJumbledWords.removeAll(wordsViewedByUser);
		Object[] words = allJumbledWords.toArray();
		if (words.length == 0) {
			throw new IllegalStateException(
					"There are no more jumbled words for the user");
		} else {
			// get the first element in the array
			String newWord = (String) words[0];
			return newWord;
		}
	}

	/**
	 * Checks if the set of all the jumbled words displayed to the user is equal
	 * to the set of all the jumbled words present in the repository.Helps find
	 * if we have reached end of the game.
	 * 
	 * @param wordsViewedByUser
	 * @param allJumbledWords
	 * @return boolean
	 */
	public boolean isNextJumbledWordAvailable(Set<String> wordsViewedByUser,
			Set<String> allJumbledWords) {
		return !allJumbledWords.equals(wordsViewedByUser);
	}
}
